CC = /usr/local/bin/clang
OCAMLC=/usr/local/bin/ocamlc
OCAMLMKTOP=/usr/local/bin/ocamlmktop
OCAML_LIB_PATH=/usr/local/lib/ocaml

SRC_PATH=src

all: ${SRC_PATH}/common.cmo ${SRC_PATH}/getpass.o \
     ${SRC_PATH}/charset_convert.o ${SRC_PATH}/io.cmo \
     ${SRC_PATH}/ftp_session.cmo ${SRC_PATH}/ftp_core.cmo \
     ${SRC_PATH}/ftp_file_info.cmo ${SRC_PATH}/error.cmo \
     ${SRC_PATH}/glob.o ${SRC_PATH}/glob.cmo ${SRC_PATH}/cmd.cmo \
     ${SRC_PATH}/toplevel.cmo ${SRC_PATH}/mlftp.cmo
	cd ${SRC_PATH}; \
    ${OCAMLC} -o mlftp -custom \
              ${OCAML_LIB_PATH}/unix.cma ${OCAML_LIB_PATH}/str.cma \
              common.cmo charset_convert.o getpass.o io.cmo ftp_session.cmo \
              ftp_core.cmo ftp_file_info.cmo error.cmo glob.o glob.cmo \
              cmd.cmo toplevel.cmo mlftp.cmo

top: ${SRC_PATH}/common.cmo ${SRC_PATH}/getpass.o \
     ${SRC_PATH}/charset_convert.o ${SRC_PATH}/io.cmo \
     ${SRC_PATH}/ftp_session.cmo ${SRC_PATH}/ftp_core.cmo \
     ${SRC_PATH}/ftp_file_info.cmo ${SRC_PATH}/error.cmo \
     ${SRC_PATH}/glob.o ${SRC_PATH}/glob.cmo ${SRC_PATH}/cmd.cmo \
     ${SRC_PATH}/toplevel.cmo 
	cd ${SRC_PATH};\
    ${OCAMLMKTOP} -o mlftp_top -custom \
                  ${OCAML_LIB_PATH}/unix.cma ${OCAML_LIB_PATH}/str.cma \
                  common.cmo charset_convert.o getpass.o io.cmo \
                  ftp_session.cmo ftp_core.cmo ftp_file_info.cmo error.cmo \
                  glob.o glob.cmo cmd.cmo toplevel.cmo

clean:
	rm -f ${SRC_PATH}/*.o
	rm -f ${SRC_PATH}/*.cm*
	rm -f ${SRC_PATH}/mlftp
	rm -f ${SRC_PATH}/mlftp_top

${SRC_PATH}/common.cmo: ${SRC_PATH}/common.ml
	cd ${SRC_PATH}; \
    ${OCAMLC} -c common.ml -o common.cmo

${SRC_PATH}/charset_convert.o: ${SRC_PATH}/charset_convert.c
	cd ${SRC_PATH}; \
    ${CC} -c -I/usr/local/lib/ocaml charset_convert.c

${SRC_PATH}/getpass.o: ${SRC_PATH}/getpass.c
	cd ${SRC_PATH}; \
    ${CC} -c -I/usr/local/lib/ocaml getpass.c

${SRC_PATH}/io.cmo: ${SRC_PATH}/charset_convert.o ${SRC_PATH}/getpass.o \
                    ${SRC_PATH}/io.ml 
	cd ${SRC_PATH}; \
    ${OCAMLC} -c io.ml -o io.cmo

${SRC_PATH}/ftp_session.cmo: ${SRC_PATH}/common.cmo ${SRC_PATH}/io.cmo \
                             ${SRC_PATH}/ftp_session.ml
	cd ${SRC_PATH}; \
    ${OCAMLC} -c ftp_session.ml -i ftp_session.cmo

${SRC_PATH}/ftp_core.cmo: ${SRC_PATH}/common.cmo ${SRC_PATH}/io.cmo \
                          ${SRC_PATH}/ftp_session.cmo ${SRC_PATH}/ftp_core.ml
	cd ${SRC_PATH}; \
    ${OCAMLC} -c ftp_core.ml -o ftp_core.cmo

${SRC_PATH}/ftp_file_info.cmo: ${SRC_PATH}/common.cmo ${SRC_PATH}/io.cmo \
                               ${SRC_PATH}/ftp_session.cmo \
                               ${SRC_PATH}/ftp_core.cmo \
                               ${SRC_PATH}/ftp_file_info.ml
	cd ${SRC_PATH}; \
    ${OCAMLC} -c ftp_file_info.ml -o ftp_file_info.cmo

${SRC_PATH}/error.cmo: ${SRC_PATH}/common.cmo ${SRC_PATH}/io.cmo \
                       ${SRC_PATH}/error.ml
	cd ${SRC_PATH}; \
    ${OCAMLC} -c error.ml -o error.cmo

${SRC_PATH}/glob.o: ${SRC_PATH}/glob.c
	cd ${SRC_PATH}; \
    ${CC} -c -I/usr/local/lib/ocaml glob.c

${SRC_PATH}/glob.cmo: ${SRC_PATH}/common.cmo ${SRC_PATH}/io.cmo \
                      ${SRC_PATH}/ftp_session.cmo \
                      ${SRC_PATH}/ftp_core.cmo \
                      ${SRC_PATH}/glob.o ${SRC_PATH}/glob.ml
	cd ${SRC_PATH}; \
    ${OCAMLC} -c glob.ml -o glob.cmo

${SRC_PATH}/cmd.cmo: ${SRC_PATH}/common.cmo ${SRC_PATH}/io.cmo \
                     ${SRC_PATH}/ftp_session.cmo \
                     ${SRC_PATH}/ftp_core.cmo \
                     ${SRC_PATH}/ftp_file_info.cmo \
                     ${SRC_PATH}/error.cmo \
                     ${SRC_PATH}/glob.cmo \
                     ${SRC_PATH}/cmd.ml
	cd ${SRC_PATH}; \
    ${OCAMLC} -c cmd.ml -o cmd.cmo

${SRC_PATH}/toplevel.cmo: ${SRC_PATH}/common.cmo ${SRC_PATH}/io.cmo \
                          ${SRC_PATH}/ftp_session.cmo \
                          ${SRC_PATH}/ftp_core.cmo \
                          ${SRC_PATH}/error.cmo \
                          ${SRC_PATH}/cmd.cmo \
                          ${SRC_PATH}/toplevel.ml
	cd ${SRC_PATH}; \
    ${OCAMLC} -c toplevel.ml -o toplevel.cmo

${SRC_PATH}/mlftp.cmo: ${SRC_PATH}/common.cmo ${SRC_PATH}/io.cmo \
                       ${SRC_PATH}/toplevel.cmo ${SRC_PATH}/mlftp.ml
	cd ${SRC_PATH}; \
    ${OCAMLC} -c mlftp.ml -o mlftp.cmo
